module repository.UserAssetsRepository;

import bootstrap.DatabaseBootstrap;
import hunt.entity;
import hunt.logging;
import std.conv : to;
import model;
import message.MsgDefine;
import core.stdc.time;

import hunt.framework;

class UserAssetsRepository : EntityRepository!( UserAssets , int){

  this()
  {
    super( defaultEntityManager());
  }


  UserAssets getStatus(int id)
  {
    scope(exit)
    {
      _manager.close();
    }
    auto query = _manager.createQuery!(UserAssets)("select * from UserAssets a where a.id = :id for update").
    setParameter("id", id);
    UserAssets[] objs = query.getResultList();
    if(objs.length != 0)
    {
      return objs[0];
    }else
    {
      return null;
    }
  }

  void putUserAssets (UserAssets obj)
  {
      insert(obj);
  }

  void updateUserAssets(ulong asset,ulong userId, EntityManager em)
  {
    auto update = em.createQuery!(UserAssets)("UPDATE UserAssets u SET u.assets = :assets WHERE u.id = :userId");
    update.setParameter("assets",asset);
    update.setParameter("userId",userId);
    update.exec();
  }

}
